package lxt.dao.impl;

import java.util.ArrayList;
import java.util.List;

import lxt.dao.CostAccidentDao;
/**
 * 交通事故管理dao
 * @author Lit
 *
 */
public class CostAccidentDaoImpl extends ABseDaoImpl implements CostAccidentDao {
	/**
	 * 根据具体信息查询
	 */
	@SuppressWarnings("unchecked")
	public List<Object> loadAllCostAccident(String truckId,String driverId,int offset, int length){
		StringBuffer hql = new StringBuffer("Select tc,td.name from CostAccident tc,DriverInfo td where tc.driverId = td.driverId ");
		ArrayList<Object> param = new ArrayList<Object>();
		if(truckId!=null&&!truckId.equals("")){
			hql.append(" And tc.truckId like ? ");
			param.add("%"+truckId+"%");
		}
		if(driverId!=null&&!driverId.equals("")){
			hql.append(" And td.name like ? ");
			param.add("%"+driverId+"%");
		}

		return (List<Object>) this.queryForPage(hql.toString(), param, offset, length);
		
	}
	/**
	 * 查询数量
	 */
	public int loadAllCostAccidentCount(String truckId,String driverId){
		StringBuffer hql = new StringBuffer("Select tc,td.name from CostAccident tc,DriverInfo td where tc.driverId = td.driverId ");
		ArrayList<Object> param = new ArrayList<Object>();
		if(truckId!=null&&!truckId.equals("")){
			hql.append(" And tc.truckId like ? ");
			param.add("%"+truckId+"%");
		}
		if(driverId!=null&&!driverId.equals("")){
			hql.append(" And td.name like  ? ");
			param.add("%"+driverId+"%");
		}
		return this.getAllRowCount(hql.toString(), param);
	}
}
